package com.mtk.launcher.util;

import android.content.Context;
import android.content.Intent;
import android.provider.Settings;

import com.lark.wifi.util.MyLog;
import com.mtk.launcher.BuildConfig;

public class DateAndTimeUtil {
    static final String HOURS_12 = "12";
    static final String HOURS_24 = "24";

    public static void setAutoTime(Context context, int value) {
        if (BuildConfig.DEBUG) {
            return;
        }
        // 启用自动同步
        Settings.Global.putInt(
                context.getContentResolver(),
                Settings.Global.AUTO_TIME,
                value
        );
    }

    /***
     * 是否自动同步网络时间
     * @param context
     * @return
     */
    public static boolean getAutoTime(Context context) {
        if (BuildConfig.DEBUG) {
            return false;
        }
        int backNum = Settings.System.getInt(
                context.getContentResolver(),
                Settings.Global.AUTO_TIME,
                0
        );
        MyLog.cdl("getAutoTime==" + backNum);
        return backNum == 1;
    }

    public static void set24Hour(Context context, Boolean is24Hour) {
        if (BuildConfig.DEBUG) {
            return;
        }
        String value = is24Hour == null ? null :
                is24Hour ? HOURS_24 : HOURS_12;
        Settings.System.putString(context.getContentResolver(),
                Settings.System.TIME_12_24, value);
        //通知系统更新时间
        Intent timeChangedIntent = new Intent(Intent.ACTION_TIME_CHANGED);
        context.sendBroadcast(timeChangedIntent);
    }

    /***
     * true 24小时
     * false 12小时
     * @param context
     * @return
     */
    public static boolean get24Hour(Context context) {
        if (BuildConfig.DEBUG) {
            return false;
        }
        String values = Settings.System.getString(
                context.getContentResolver(),
                Settings.System.TIME_12_24);

        MyLog.cdl("get24Hour=="+values);
        if (values.equals(HOURS_24)) {
            return true;
        }
        return false;
    }

}



